function setCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
        {
            return unescape(y);
        }
    }
}

var timer = jQuery.timer(function() {
    if(jQuery("#refresh_checkbox").attr("checked")){
        location.reload(true);
    }
});
    
function pageAutoRefreshTimeReload(_time_reload)
{
    var split = document.URL.split('/');
    var url = split.pop();
    if(url == '')
        prefix = split.pop();
    else{
        var urlparts = url.split('?'); 
        var prefix = urlparts[0];
    }
    
    jQuery("#refresh_checkbox").click(function(){
        if(jQuery("#refresh_checkbox").attr("checked")){
            timer.play();
            setCookie(prefix + "_refresh", "true");
            jQuery("#refresh_checkbox").attr("title", "Unset Refresh per 1 menit");
        }else{
            timer.pause();
            setCookie(prefix + "_refresh", "false");
            jQuery("#refresh_checkbox").attr("title", "Set Refresh per 1 menit");
        }
    });

    if(getCookie(prefix + "_refresh") == "true"){
        jQuery("#refresh_checkbox").attr("checked", "checked").attr("title", "Unset Refresh per 1 menit");
    }

    timer.set({ time : _time_reload, autostart : true});
}


function pageAutoRefresh()
{
    var split = document.URL.split('/');
    var url = split.pop();
    if(url == '')
        prefix = split.pop();
    else{
        var urlparts = url.split('?'); 
        var prefix = urlparts[0];
    }
    
    jQuery("#refresh_checkbox").click(function(){
        if(jQuery("#refresh_checkbox").attr("checked")){
            timer.play();
            setCookie(prefix + "_refresh", "true");
            jQuery("#refresh_checkbox").attr("title", "Unset Refresh per 5 detik");
        }else{
            timer.pause();
            setCookie(prefix + "_refresh", "false");
            jQuery("#refresh_checkbox").attr("title", "Set Refresh per 5 detik");
        }
    });

    if(getCookie(prefix + "_refresh") == "true"){
        jQuery("#refresh_checkbox").attr("checked", "checked").attr("title", "Unset Refresh per 5 detik");
    }

    timer.set({ time : 5000, autostart : true});
}